package com.shzq.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.shzq.constant.GradeEnum;
import com.shzq.pojo.Node;
import com.shzq.service.ArithmeticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.Point;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/arithmetic")
public class AnalyzeController {

    @Autowired
    private ArithmeticService arithmeticService;

    @RequestMapping("/getDbScan")
    public List<Map<String,Object>> getDbScanData(){
        Random random = new Random();
        GradeEnum[] grades = GradeEnum.values();
        List<Map<String,Object>> result = new ArrayList<>();
        List<List<double[]>> list = arithmeticService.doDbScan();
        for (List<double[]> doubles : list) {
           List<double[]> collect = doubles.stream().filter(s -> random.nextInt(4) == 1).collect(Collectors.toList());
            HashMap<String, Object> child = new HashMap<>();
            GradeEnum grade = grades[random.nextInt(grades.length)];
            child.put("src",grade.getSrc());
            child.put("data",collect);
            result.add(child);
        }
        return result;
    }

    @RequestMapping("/dbflash")
    public String flashDbScan(){
        new Thread(()->arithmeticService.createData()).start();
        return "请求成功";
    }
}
